package cn.hbu.zlfw.common.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.hbu.zlfw.admin.entity.Expert;
import cn.hbu.zlfw.admin.entity.ScienceExpert;
import cn.hbu.zlfw.admin.entity.UnitAdmin;
import cn.hbu.zlfw.dic.service.DicSubjectService;
import cn.hbu.zlfw.patent.entity.Patent;

/**
 * 
 * @ClassName: PatentUtil 
 * @Description: 学科字典工具类
 * @author 王鹏伟<1223443289@qq.com>
 * @date 2017年12月12日 下午2:42:44 
 * @vsersion:v1.0
 */
public class DicSubjectUtil {
	/**
	 * @Title: parseSubject 
	 * @Description: 将专利学科编码转换成描述
	 * @return Map<String,String>
	 * @throws
	 */
	public  static Map<String, String> parseSubjectByPatents(List<Patent> patents,DicSubjectService dicSubjectService) {
		Map<String, String> patentSubjectsMap = new HashMap<String, String>();
		for (int i = 0; i < patents.size(); i++) {
			patentSubjectsMap.put(patents.get(i).getId(),parseSubjectCode(patents.get(i).getSubjectTypes(),dicSubjectService));
		}
		return patentSubjectsMap;
	}
	/**
	 * @Title: parseSubject 
	 * @Description: 将科技服务人员学科编码转换成描述
	 * @return Map<String,String>
	 * @throws
	 */
	public static Map<String, String> parseSubjectByScienceExperts(List<ScienceExpert> scienceExperts,
			DicSubjectService dicSubjectService) {
		Map<String, String> patentSubjectsMap = new HashMap<String, String>();
		for (int i = 0; i < scienceExperts.size(); i++) {
			patentSubjectsMap.put(scienceExperts.get(i).getId(),parseSubjectCode(scienceExperts.get(i).getSubjectTypes(),dicSubjectService));
		}
		return patentSubjectsMap;
	}
	/**
	 * @Title: parseSubject 
	 * @Description: 将专家学科编码转换成描述
	 * @return Map<String,String>
	 * @throws
	 */
	public static Map<String, String> parseSubjectByExperts(List<Expert> experts,
			DicSubjectService dicSubjectService) {
		Map<String, String> patentSubjectsMap = new HashMap<String, String>();
		for (int i = 0; i < experts.size(); i++) {
			patentSubjectsMap.put(experts.get(i).getId(),parseSubjectCode(experts.get(i).getSubjectTypes(),dicSubjectService));
		}
		return patentSubjectsMap;
	}
	/**
	 * 
	 * @Title: parseSubjectByUnitAdmins 
	 * @Description: 将单位管理员学科编码转换成描述
	 * @return Object 
	 * @throws
	 */
	public static Object parseSubjectByUnitAdmins(List<UnitAdmin> unitAdmins, DicSubjectService dicSubjectService) {
		Map<String, String> patentSubjectsMap = new HashMap<String, String>();
		for (int i = 0; i < unitAdmins.size(); i++) {
			patentSubjectsMap.put(unitAdmins.get(i).getId(),parseSubjectCode(unitAdmins.get(i).getSubjectTypes(),dicSubjectService));
		}
		return patentSubjectsMap;
	}
	
	
	//处理单个专利所属学科描述的查询
	private  static String parseSubjectCode(String subjectTypes,DicSubjectService dicSubjectService) {
		String[] subjectCodes=subjectTypes.split(",");
		String[] subjects=new String[subjectCodes.length];
		StringBuffer sbfsubjects=new StringBuffer();
		for (int i = 0; i < subjectCodes.length; i++) {
			subjects[i]= dicSubjectService.getSubjectByCode(Integer.valueOf(subjectCodes[i]));
		}
		for (int i = 0; i < subjects.length; i++) {
			if(i==(subjects.length-1)) {
				sbfsubjects.append(subjects[i]);
			}else {
				sbfsubjects.append(subjects[i]+",");
			}
		}	
		return sbfsubjects.toString();
	}
	
}
